package com.st.warehouse.ui.navbar;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;

import com.st.warehouse.R;
import com.st.warehouse.ui.activity.LoginActivity;
import com.st.warehouse.utils.SystemUtils;

public class MyFragment extends Fragment {
    private final String TAG = "MyFragment";
    private static MyFragment myFragment;
    private View rootView;
    private LinearLayout login;
    private RelativeLayout rl_title;
    private ImageView userImage;

    public MyFragment() {
    }
    //单例创建
    public static MyFragment getInstance(){
        if (myFragment == null) return new MyFragment();
        return myFragment;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        if (rootView == null){
            rootView = inflater.inflate(R.layout.fragment_my, container, false);
            initView();
            linster();
        }
        Log.d("test", "onCreateView:MyFragment ");
        return rootView;
    }
    private void initView() {
        //状态栏设置
        getActivity().getWindow().setStatusBarColor(getActivity().getColor(R.color.transparent));
        getActivity().getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);//字体黑色
        // 隐藏 Activity 的 ActionBar
        ActionBar actionBar = ((AppCompatActivity) getActivity()).getSupportActionBar();
        if (actionBar != null) {
            actionBar.hide();
        }
        //getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);

        login = rootView.findViewById(R.id.login);
        userImage = rootView.findViewById(R.id.userImage);
        // 当前版本
        TextView version = rootView.findViewById(R.id.version);
        String versionY = "版本：" + SystemUtils.getVersionName(getActivity());
        version.setText(versionY);

    }
    private void linster() {
        login.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(getActivity(), LoginActivity.class);
                startActivity(intent);
            }
        });
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        Log.d(TAG, "onDestroy: MyFragment");
    }
}